package com.zzl.springboot_mybatis_demo.controller.responseentity;

import com.gitee.yongzhuzl.commonutil.util.date.CalendarUtil;
import com.gitee.yongzhuzl.commonutil.util.random.RandomUtil;
import com.zzl.springboot_mybatis_demo.entity.common.CommonEntity;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpStatus;
import org.springframework.http.ResponseEntity;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestMapping;

import java.util.HashMap;
import java.util.Map;

/**
 * Description：模拟订单Controller（本质是学习ResponseEntity对象的使用）
 * Created by 朱正磊 on 2019-08-24 10:45
 */
@Controller
@RequestMapping("/api/admin/order")
public class AdminOrderController {

    @RequestMapping("/findOrderByOrderCode/{orderCode}")
    public ResponseEntity<?> findOrderByOrderCode(@PathVariable String orderCode) {
        return new ResponseEntity<>("订单编号：" + orderCode, HttpStatus.OK);
    }

    @RequestMapping("/findOrderByUserName/{userName}")
    public ResponseEntity<?> findOrderByUserName(@PathVariable String userName) {
        return ResponseEntity.ok(userName);
    }

    @RequestMapping("/customHeader")
    public ResponseEntity<?> customHeader() {
        HttpHeaders headers = new HttpHeaders();
        headers.add("Custom-Header", "foo");
        return new ResponseEntity<>("Custom header set", headers, HttpStatus.OK);
    }

    @RequestMapping("/createOrder")
    public ResponseEntity<?> createOrder() {
        Map<String, Object> order = new HashMap<>();
        order.put("orderCode", RandomUtil.getUuidNoLine());
        order.put("userName", "zzl");
        order.put("createTime", CalendarUtil.getNowDate());
        CommonEntity commonEntity = CommonEntity.build(200, "创建订单成功！", order);
        return ResponseEntity.ok(commonEntity);
    }

}
